package rd.android.hardcore.engine.air 
{
	import air.update.ApplicationUpdater;
	import air.update.ApplicationUpdaterUI;
	import air.update.events.StatusUpdateEvent;
	import air.update.events.UpdateEvent;
	import flash.events.EventDispatcher;
	
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class HardcoreUpdater extends EventDispatcher
	{
		public var appUpdater:ApplicationUpdaterUI;
		//public var appUpdater:ApplicationUpdater;
		
		public function HardcoreUpdater() 
		{
			appUpdater = new ApplicationUpdaterUI();
		}
		
		
		private function updateCheckNow(e:UpdateEvent):void 
		{
			
			readyToCheck();
			//UpdaterConfiguration
		}
		
		
		
		private function readyToCheck():void
		{
			appUpdater.checkNow();
		}
		
		/**
		 * @TODO Change applicationupdater_UI pour corriger l'exception sur initialize
		 * @param	_maj_url
		 */
		public function Maj(_maj_url:String):void
		{
			appUpdater.addEventListener(UpdateEvent.INITIALIZED, updateCheckNow);
			appUpdater.addEventListener(UpdateEvent.BEFORE_INSTALL, beforeInstall);
			appUpdater.addEventListener(UpdateEvent.DOWNLOAD_COMPLETE, downloadComplete);
			appUpdater.addEventListener(UpdateEvent.DOWNLOAD_START, downloadStart );
			appUpdater.addEventListener(UpdateEvent.CHECK_FOR_UPDATE, checkForUpdate );
			appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, updateStatus);
			appUpdater.updateURL = _maj_url;
			appUpdater.delay = 0.1;
			appUpdater.isCheckForUpdateVisible = false;
			//appUpdater.initialize();
		}
		
		private function updateStatus(e:StatusUpdateEvent):void 
		{
			trace("statusEvent"+e.available);
			trace("statusEvent"+e.details);
		}
		
		private function checkForUpdate(e:UpdateEvent):void 
		{
			trace("checkForUpdate");
		}
		
		private function downloadStart(e:UpdateEvent):void 
		{
			trace("downloadStart");
		}
		
		private function downloadComplete(e:UpdateEvent):void 
		{
			trace("downloadComplete");
		}
		
		private function beforeInstall(e:UpdateEvent):void 
		{
			trace("beforeInstall");
		}
		
	}

}